﻿Imports System.Collections.Generic
Imports System.Data
Imports CondorTravel.BC
Imports CondorTravel.BE
Imports CondorTravelUTIL.DL

Public Class BuscarCliente
    Inherits System.Web.UI.Page

    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


    End Sub


    Private Sub ListarCliente()

        Dim objClienteBE As New ClienteBE
        Dim objClienteBC As New ClienteBC
        Dim bExito As Boolean = False
        Dim sMensaje As String = String.Empty

        objClienteBE.NomCLi = txtRazonSocial.Text.Trim

        dgCliente.DataSource = objClienteBC.ListaCliente(objClienteBE)
        dgCliente.DataBind()

        If dgCliente.Rows.Count <= 0 Then
            dgCliente.Visible = False
            lblError.Visible = True
        Else
            dgCliente.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarCliente()
    End Sub

    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click

        Dim dt As New DataTable
        Dim sNombre As String = String.Empty
        Dim sRuc As String = String.Empty
        Dim scadena As String

        For Each Me.itemgridview In dgCliente.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                sNombre = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sRuc = CType(itemgridview.FindControl("lblRuc"), Label).Text
            End If

        Next
        scadena = sNombre

        'Response.Write("<script language=Javascript>window.opener.location.reload();</script>")
        Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BCNombreCliente") = sNombre 

    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub
End Class